﻿using Mapster;
using System;

namespace MapsterProj
{
    /*
     
     https://github.com/MapsterMapper/Mapster
     
    Mapster 内部应该使用的 静态构造函数原理，全局用 TypeAdapterConfig 配置类型对应，使用上更简便，效率更高。

    AutoMapper 设计的更专业，但从拿来即用，快速上手上，没有 Mapster 简便。
     
     */
    class Program
    {
        static void Main(string[] args)
        {
            var foo = new Foo() { id = 1, name = "foo", added = DateTime.Now };
            var bar = new Bar() { id = 1, name = "bar", added = DateTime.Now };


            var foo_dto = foo.Adapt<FooDto>();

            //只有属性名称相同，才赋值
            var Bar_dto = bar.Adapt<BarDto>();

            TypeAdapterConfig<Bar, BarDto>.NewConfig()
                .Map(d => d.bid, s => s.id)
                .Map(d => d.bar_name, s => s.name);

           var Bar_dto2 = bar.Adapt<BarDto>();


        }
    }
    public class Foo
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }

    }
    public class FooDto
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }
    }
    public class Bar
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }
    }
    public class BarDto
    {
        public long bid { get; set; }
        public string bar_name { get; set; }
        public DateTime added { get; set; }
    }
}
